<center>
	<font size=7 class='titre'>Modifier un appartement</font><br /> <br />
</center>
<?php
if (isset($_POST['appart_a_modifier'])) {
	//on modifie l'appart ici
	$id_appart_a_modifier = secure ($_POST['appart_a_modifier']);
	$nom = secure ($_POST['nom']);
	$pays = secure ($_POST['pays']);
	$ville = secure ($_POST['ville']);
	$adresse = secure ($_POST['adresse']);
	$description = secure ($_POST['description']);
	$caracteristiques = secure ($_POST['caracteristiques']);
	$superficie = secure ($_POST['superficie']);
	$chambres = secure ($_POST['chambres']);
	$sdb = secure ($_POST['sdb']);
	$wc = secure ($_POST['wc']);
	$jardin = secure ($_POST['jardin']);
	$format = secure ($_POST['format']);
	$type = secure ($_POST['type']);
	$prix = secure ($_POST['prix']);

	connect ($link);
	$query = 'UPDATE `biens` SET `nom`=\''.$nom.'\', `pays`=\''.$pays.'\', `ville`=\''.$ville.'\', `adresse`=\''.$adresse.'\', `description`=\''.$description.'\', `superficie`=\''.$superficie.'\', `nb_chambres`=\''.$chambres.'\', `sdb`=\''.$sdb.'\', `wc`=\''.$wc.'\', `jardin`=\''.$jardin.'\', `type`=\''.$type.'\', `format`=\''.$format.'\', `caracteristiques`=\''.$caracteristiques.'\', `prix`=\''.$prix.'\' WHERE id=\''.$id_appart_a_modifier.'\'';
	$res = mysql_query($query) or die("Impossible de rajouter l'appartement das la bdd.");
	deconnect($link);
} else if (isset($_GET['appart_a_modifier'])) {
	$id_appart_a_modifier = secure ($_GET['appart_a_modifier']);
} else {
	header('Location: admin.html');
}

$row = get_appart_informations($id_appart_a_modifier);
?>
<form action='' method=post>
	<table border=1 cellpadding='5px' cellspacing='10px'>
		<input type=hidden name=appart_a_modifier value="<?php echo $id_appart_a_modifier?>" />
		<tr>
			<td>Nom</td>
			<td><input name=nom size=30 value='<?php echo $row['nom'];?>'/></td>
		</tr>
		<tr>
			<td>Pays</td>
			<td><?php list_countries_preremplie ($row['pays']); ?></td>
		</tr>
		<tr>
			<td>Ville</td>
			<td><?php list_cities_preremplie ($row['ville']); ?></td>
		</tr>
		<tr>
			<td>Adresse</td>
			<td><textarea cols=40 rows=2 name=adresse><?php echo $row['adresse'];?></textarea></td>
		</tr>
		<tr>
			<td>Description</td>
			<td><textarea cols=40 rows=5 name=description><?php echo $row['description'];?></textarea></td>
		</tr>
		<tr>
			<td>Caracteristiques</td>
			<td><textarea cols=40 rows=5 name=caracteristiques><?php echo $row['caracteristiques'];?></textarea></td>
		</tr>
		<tr>
			<td>Superficie</td>
			<td><input name=superficie type=number  value='<?php echo $row['superficie'];?>'/> m<sup>2</sup></td>
		</tr>
		<tr>
			<td>Chambres</td>
			<td><?php liste_nombres_prerempli ('chambres', 15, $row['nb_chambres']); ?></td>
		</tr>
		<tr>
			<td>Salle de Bain</td>
			<td><?php liste_nombres_prerempli ('sdb', 5, $row['sdb']); ?></td>
		</tr>
		<tr>
			<td>WC</td>
			<td><?php liste_nombres_prerempli ('wc', 5, $row['wc']); ?></td>
		</tr>
		<tr>
			<td>Jardin</td>
			<td><select name=jardin>
			<?php 
			if ($row['jardin'] == 1) {
				echo'<option selected=selected value=1>oui</option>
				<option value=0>non</option>';
			} else {
				echo'<option value=1>oui</option>
				<option selected=selected value=0>non</option>';
			}
			?>
					
			</select>
			</td>
		</tr>
		<tr>
			<td>Type</td>
			<td><?php list_types_prerempli ($row['type']); ?></td>
		</tr>
		<tr>
			<td>Format</td>
			<td><?php list_formats_prerempli ($row['format']); ?></td>
		</tr>
		<tr>
			<td>Prix</td>
			<td><input name=prix type=text  value='<?php echo $row['prix'];?>' /> &euro;</td>
		</tr>
		<tr>
			<td colspan=2>
				<center>
					<input type=submit value='Modifier cet Appartement' />
				</center>
			</td>
		</tr>
	</table>
</form>
